package com.utils.failureanalysis.data.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.ZipFile;

public class ReadZip {
    public static void main(String[] args) throws IOException {
        new ReadZip().read();
    }

    String line;

    void read() throws IOException {

        ZipFile deviceLog = new ZipFile("./src/host_log_2910328503940944160.zip");
//		File deviceLog=new File("./src/test_result.xml");
        BufferedReader br = new BufferedReader(new InputStreamReader(deviceLog.getInputStream(deviceLog.entries().nextElement()), "GBK"));
        try {
            while ((line = br.readLine()) != null) {
//			System.out.println(line);
//			仅解析出fail条目，如果需要解析出所有条目，使用正则：".* pass$|.* fail:.*"
                if (line.matches(".* fail:.*")) {
                    String date = line.split(" ")[0] + " " + line.split(" ")[1];
                    String caseName = line.split("] ")[1].split(" ")[0];
                    System.out.println(date + " " + caseName);
                }
            }
        } catch (Throwable e) {
            System.out.println(line);
            throw e;
        }
        br.close();
    }

}
